<template>
    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
        <el-form-item label="修改的名称" prop="name">
            <el-input v-model="ruleForm.name"></el-input>
        </el-form-item>
        <el-form-item label="修改的地址" prop="name">
            <el-input v-model="ruleForm.address"></el-input>
        </el-form-item>
        <el-form-item label="修改的时间" required>
            <el-col :span="11">
                <el-form-item prop="date1">
                    <el-date-picker type="date" placeholder="选择日期" v-model="ruleForm.date"
                        style="width: 100%;"></el-date-picker>
                </el-form-item>
            </el-col>

        </el-form-item>
        <el-form-item>
            <el-button type="primary" @click="submitForm()">立即更改</el-button>
            <el-button @click="resetForm('ruleForm')">重置</el-button>
        </el-form-item>
    </el-form>
</template>
<script>
import axios from 'axios';
import moment from 'moment';
export default {
    data() {
        return {
            id: 0,
            ruleForm: {
                name: this.$store.state.Update.name,
                region: '',
                date: this.$store.state.Update.date,
                address: this.$store.state.Update.address,
            },
            rules: {
                name: [
                    { required: true, message: '请输入活动名称', trigger: 'blur' },
                    { min: 1, max: 5, message: '长度在 1 到 10 个字符', trigger: 'blur' }
                ],
                region: [
                    { required: true, message: '地址', trigger: 'change' }
                ],
                date1: [
                    { type: 'date', required: true, message: '请选择日期', trigger: 'change' }
                ],
            }
        };
    },
    methods: {
        submitForm() {
            axios({
                method: 'put',
                url: "http://localhost:8090/Goods/UPGoods",
                params: {
                    address: this.ruleForm.address,
                    name: this.ruleForm.name,
                    date: moment(this.ruleForm.date).format("YYYY-MM-DD"),
                    id: this.$store.state.Update.id
                }
            }).then(res => {
                alert('添加成功')
                this.$router.go(-1)
            }
            ).catch(error => {
                console.log(error.response)
            })
        },
        resetForm() {
            this.ruleForm.name = '',
                this.ruleForm.date = '',
                this.ruleForm.address = ''
        }
    }
}
</script>
<style scoped>
.el-form {
    width: 500px;
    margin-left: 300px;
    margin-top: 50px;
}
</style>